Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Corrects API mismatches in JWT authentication cookbook recipe based on code review feedback for PR #80.

JWT Claims Structure

  • Added required exp: usize field to Claims struct (JWT validation fails without it due to validate_exp: true default)
  • Removed misleading comment suggesting exp is optional

Token Creation

  • Fixed create_token signature: uses 2 parameters (claims, secret), not 3
  • Added proper expiration calculation using SystemTime::now() in login handler
  • Set exp in Claims before calling create_token

Framework Consistency

  • Changed #[tokio::main]#[rustapi::main] to match other recipes
  • Fixed JwtLayer instantiation: JwtLayer::<Claims>::new(secret) with type parameter
  • Removed invalid .with_algorithm() call (HS256 is default, use .with_validation() if customization needed)

Minor Fixes

  • Fixed typo in quickstart: "This commands sets up" → "This command sets up"

All changes align with actual rustapi-extras v0.1.233 implementation.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Tuntii <121901995+Tuntii@users.noreply.github.com>
Copilot AI changed the title [WIP] Update cookbook recipes to match v0.1.233 API docs: fix JWT auth recipe API errors from review feedback Feb 1, 2026
Copilot AI requested a review from Tuntii February 1, 2026 15:50
@Tuntii Tuntii marked this pull request as ready for review February 1, 2026 17:30
Copilot AI review requested due to automatic review settings February 1, 2026 17:30
@Tuntii Tuntii merged commit 56dcb43 into docs-update-cookbook-v0.1.233-1962074576845807621 Feb 1, 2026
2 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects API mismatches and improves clarity in the JWT authentication cookbook recipe, ensuring alignment with the actual rustapi-extras v0.1.233 implementation. The changes address technical inaccuracies identified during review of PR #80.

Changes:

  • Updated Claims struct comment to clarify that exp field is required for JWT expiration validation (which defaults to enabled)
  • Fixed expiration calculation by properly computing the timestamp using SystemTime::now() and storing it in a clearly-named expiration variable before assignment
  • Corrected JwtLayer instantiation to use explicit type parameter syntax: JwtLayer::<Claims>::new(secret)


// Calculate expiration (1 hour from now)
let exp = SystemTime::now()
use std::time::{SystemTime, UNIX_EPOCH};
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import statement is redundant. SystemTime and UNIX_EPOCH are already imported at line 47 at the top of the code block. The inline import should be removed.

Suggested change
use std::time::{SystemTime, UNIX_EPOCH};

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant